def test():
    num = 10
    def test2():
        num = 666
        print(num)
        print('xxx')
    print(num)
    test2()
    print(num)
    return test2

result = test()

print('---内外层分割---')
result()

# nonlocal
def test2():
    num = 10
    def test2():
        nonlocal num
        num = 666
        print(num)
        print('xxx')
    print(num)
    test2()
    print(num)
    return test2

result2 = test2()

print('---内外层分割---')
result2()


